package com.ctrip.demo.gson;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.util.ArrayList;
import java.util.List;

public class GsonTest {

    public static void main(String[] args) {
        User user1 = new User("张三",1001);
        User user2 = new User("李四",1002);
        User user3 = new User("王五",1003);

        List<User> userList = new ArrayList<>();
        userList.add(user1);
        userList.add(user2);
        userList.add(user3);

        Gson gson = new GsonBuilder().disableHtmlEscaping().setDateFormat("yyyy-MM-dd HH:mm:ss").create();
        String s = gson.toJson(userList);

        System.out.println(s);

        List<User> json = (List<User>)gson.fromJson(s, List.class);

        System.out.println(json);


    }
}
